Блог им. vldtar |Пример рабочей торговой системы на MQL5 с выходом по времени

#property copyright "Copyright 2019, Example Inc."
#property link      "https://www.example.com"

input int LotSize = 1;
input int Period = 30;
input double VolatilityThreshold = 0.1;
input int ExitAfterMinutes = 60;

int buyOrderId;
int sellOrderId;
datetime entryTime;

void OnTick()
{
    // Get the last Period candlesticks
    ArraySetAsSeries(candles, true);
    CopyRates(Symbol(), PERIOD_M1, TimeCurrent() - Period, Period, candles);

    // Calculate the maximum and minimum prices
    double maxPrice = High(candles);
    double minPrice = Low(candles);

    // Calculate the standard deviation of the closing prices
    double stdev = iStdDev(candles, MODE_CLOSE, 0);

    // Check if the volatility is above the threshold
    if (stdev > VolatilityThreshold)
    {
        // Check if the current ask price is higher than the maximum price
        if (Ask > maxPrice)
        {
            // Place a buy order
            if (OrderSend(Symbol(), OP_BUY, LotSize, Ask, 3, 0, 0, "My order", 16384, 0, Green))
            {
                Print("Buy order placed");
                buyOrderId = OrderTicket();
                entryTime = TimeCurrent();
            }
            else
            {
                Print("Error placing buy order : ", ErrorDescription(GetLastError()));
            }
        }

        // Check if the current bid price is lower than the minimum price
        if (Bid < minPrice)
        {
            // Place a sell order
            if (OrderSend(Symbol(), OP_SELL, LotSize, Bid, 3, 0, 0, "My order", 16384, 0, Red))
            {
                Print("Sell order placed");
                sellOrderId = OrderTicket();
                entryTime = TimeCurrent();
            }
            else
            {
                Print("Error placing sell order : ", ErrorDescription(GetLastError()));
            }
        }
    }

    if (buyOrderId > 0)
    {
        if (TimeCurrent() - entryTime >= ExitAfterMinutes * 60)
        {
            if (OrderClose(buyOrderId, LotSize, Bid, 3, clrNONE))
            {
                Print("Buy order closed");
                buyOrderId = 0;
            }
            else
            {
                Print("Error closing buy order : ", ErrorDescription(GetLastError()));
            }
        }
    }

    if (sellOrderId > 0)
    {
        if (TimeCurrent() - entryTime >= ExitAfterMinutes * 60)
        {
            if (OrderClose(sellOrderId, LotSize, Ask, 3, clrNONE))
            {
                Print("Sell order closed");
                sellOrderId = 0;
            }
            else
            {
                Print("Error closing sell order : ", ErrorDescription(GetLastError()));
            }
        }
    }
}

....все тэги
UPDONW
Новый дизайн